import React, { Component } from 'react'

export default class index extends Component {
  state = {
    count:0
  }
  jia = () =>{
    const {count} = this.state
    // const {s} = this.seValue.value
    // console.log(s);
    const newValue = count + this.seValue.value * 1
    this.setState({count:newValue})
  }
  jian = () =>{
    const {count} = this.state
    const newValue = count - this.seValue.value * 1
    this.setState({count:newValue})
  }
  jiJia = () =>{
    const {count} = this.state
    if(count%2 !== 0){
      const newValue = count + this.seValue.value * 1
      this.setState({count:newValue})
    }
  }
  yiJian = () =>{
    const {count} = this.state
    setTimeout(()=>{
      const newValue = count + this.seValue.value * 1
      this.setState({count:newValue})
    },2000)
  }
  render() {
    const {count} = this.state;
    return (
      <div>
        <h2>当前的和为：{count}</h2>
        <select name="" id="" ref={(c)=>{this.seValue = c}} >
          <option value="1">1</option>
          <option value="2">2</option>
          <option value="3">3</option>
        </select>&nbsp;
        <button onClick={this.jia}>+</button>&nbsp;
        <button onClick={this.jian}>-</button>&nbsp;
        <button onClick={this.jiJia}>当前和为奇数则加</button>&nbsp;
        <button onClick={this.yiJian}>异步加</button>&nbsp;
      </div>
    )
  }
}
